<template>
  <div class="blog-home" v-if="!loading">

    <!--视频名称-->
    <div class="title-article">
      <h3>
        {{video.title}}
      </h3>
    </div>
    <!--简介-->
    <div style="margin:10px 10px; border: 1px solid #ccc;">
      <iframe :src="videoUrl"
              frameborder="0" scrolling="no" class="video" allowfullscreen>
      </iframe>
    </div>
    <div class="text-context len-context-detail">
      <ul>
        <!--内容-->
        <li>
          <div id="quill-container" class="ql-snow">
            <Tabs type="card">
              <TabPane label="课程目录">
                <div class="sy_body">
                  <div class="title"><span></span>课程大纲</div>
                  <div class="chapter_info" v-for="(one, index) in courses" :key="index">
                    <div class="chapter_name">
                      <span>&nbsp;&nbsp;&nbsp;&nbsp;第{{index + 1}}章&nbsp;&nbsp;</span>{{one.zjName}}
                    </div>
                    <div class="period_info" v-for="(two, num) in one.children" :key="num">
                      <div class="period_top" @click="videoPlay(two)">
                        <div class="period_video"></div>
                        <span v-if="two.free>0" class="no_video">(收费)</span>
                        <span v-if="two.free<1" class="c_blue">(免费)</span>
                        {{two.zjName}}
                        <span class="video_time fr">{{two.longTime}}分钟</span>
                      </div>
                    </div>
                  </div>
                </div>
              </TabPane>
              <TabPane label="课程资料">
                <div>
                  <p class="time">网盘地址：<span>{{video.link}}</span></p>
                  <p class="time" @click="reward(video.id)">网盘密码：<span>查看密码</span></p>
                </div>
              </TabPane>
            </Tabs>
          </div>
        </li>
      </ul>
    </div>
  </div>

  </div>
  <!--百度网盘地址-->

  <div v-else-if="!err">
    加载中。。。
  </div>
  <div v-else>
    <img src="../../../static/image/bd.gif"/>
    <div>404</div>
  </div>
</template>

<script>
  import blogHead from "../header/head"
  import blogRight from "../right/right"
  import blogBottom from "../bottom/bottom"
  import {parseTime} from '@/util/date'

  export default {
    components: {
      blogHead,
      blogRight,
      blogBottom,
    },
    data() {
      return {
        video: undefined,
        loading: true,
        err: false,
        previous: null,
        next: null,
        tags: [],
        courses: [],
        transition: false,
        player: null,
        videoUrl: null

      }
    },
    computed: {
      route: function () {
        return this.$route.params.code
      }
    },
    methods: {
      init() {
        let code = this.$route.params.code
        this.$http.get(`/api/resource/getDetail/${code}`).then(resp => {
          let data = resp.data.data;
          if (data == null) {
            this.video = null;
            this.loading = true;
            this.err = true;
            return;
          }
          this.video = data;
          this.loading = false;
          this.transition = true;
        }).catch(res => {

        });
      },
      course() {
        let code = this.$route.params.code
        this.$http.get(`/api/course/catalog/${code}`).then(resp => {
          let data = resp.data.data;
          if (data == null) {
            this.courses = null;
            this.loading = true;
            this.err = true;
            return;
          }
          this.courses = data;
          this.videoUrl = data[0].videoUrl;
          this.loading = false;
          this.transition = true;
        }).catch(res => {

        });
      },
      videoPlay(two) {
        if (two.free < 1) {
          this.videoUrl = two.videoUrl;
          window.scrollTo(0, 60);
          return;
        }

        this.reward(this.video.id)
      },

      index: function () {
        this.$router.push('/');
      },
      reward(id) {
        this.$router.push(`/reward/${id}`)
      },

      dateFilter(t) {
        if (t) {
          return parseTime(t)
        } else {
          return '未知'
        }
      }
    },
    mounted() {
      this.init();
      this.course();
      this.videoPlay();
      window.scrollTo(0, 60);
    },
    watch: {
      $route: {
        handler: function (val, oldVal) {
          this.init();
          window.scrollTo(0, 60);
        },
      }
    }
  }
</script>

<style scoped>
  @import "../../../static/css/quill.snow.css";
  @import "../../../static/css/quill.core.css";
  @import "../../../static/css/quill.bubble.css";
  @import "../../../static/css/blog-detail.css";
</style>
<style scoped>
  .title-article h3 {
    font-size: 28px;
    color: #333;
    font-weight: normal;
    padding-top: 30px;
  }
.video{
  width:100%;
  height:440px;
}

  .sy_body {
  }


  .title {
    border-left: 3px solid #000;
    padding-left: 12px;
    font-size: 16px;
    color: #000;
    font-weight: 700;
    margin-bottom: 25px;
  }

  .chapter_info {
    width: 839px;
    margin: 0 auto;
    font-size: 14px;
    border-bottom: 1px solid #ccc;
    margin-bottom: 30px;
    padding-bottom: 20px;
  }

  .chapter_name {
    font-size: 14px;
    font-weight: 700;
    color: #333;
    padding-bottom: 10px;
  }

  .period_info {
    position: relative;
  }

  a {
    display: inline-block;
    font-size: 12px;
    width: 66px;
    height: 26px;
    text-align: center;
    line-height: 26px;
    color: #999;
    position: absolute;
    right: 0px;
    top: 10px;
    border: 1px solid rgb(153, 153, 153);
    border-radius: 13px;
  }

  .period_top {
    width: 627px;
    padding-left: 20px;
    height: 46px;
    line-height: 46px;
    position: relative;
    padding-right: 104px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    cursor: pointer;
  }

  .video_time {
    position: absolute;
    right: 0;
  }

  .period_num {
    margin-right: 6px;
  }

  .period_video {
    display: inline-block;
    width: 21px;
    height: 21px;
    position: relative;
    top: 6px;
    margin-right: 10px;
    background: url(../../assets/video.svg) center center;
    background-size: 21px 21px;
  }
  @media screen and (max-width: 768px) {
    .video{
      width:300px;
      height:160px;
    }
  }


</style>

